function ReSetVerifyCode()
{
    var imgv = document.getElementById('verifyCodeImg');
    imgv.innerHTML = '<img src="./verifyCode.php?id='+Math.random()+'" align="absmiddle">(点击更新图片)';
}

String.prototype.trim   =   function()
{
         //   用正则表达式将前后空格
         //   用空字符串替代。
         return   this.replace(/(^\s*)|(\s*$)/g,   "");
}

function strstr (haystack, needle, bool) {
    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}


function executeScript(html)
{
    var reg = /<script[^>]*>([^\x00]+)$/i;
    //对整段HTML片段按<\/script>拆分
    var htmlBlock = html.split("<\/script>");
    for (var i in htmlBlock) 
    {
        var blocks;//匹配正则表达式的内容数组，blocks[1]就是真正的一段脚本内容，因为前面reg定义我们用了括号进行了捕获分组
        if (blocks = htmlBlock[i].match(reg)) 
        {
            //清除可能存在的注释标记，对于注释结尾-->可以忽略处理，eval一样能正常工作
            var code = blocks[1].replace(/<!--/, '');
            try 
            {
                eval(code) //执行脚本
            } 
            catch (e) 
            {
            }
        }
    }
}




function findPos(o)
{
    this.top  = o.offsetTop;
    this.left = o.offsetLeft;
    while(o = o.offsetParent)
    {
        this.top  += o.offsetTop;
        this.left += o.offsetLeft;
    }
}


//检测用户名是否可用
function checkPP(username)
{
	if(!username)
		retrun;
	var error = IsValidStr(username);	
	if(error)
	{
		$('#username_msgtext').html('<br>'+error);
		return;
	}
	$('#username_msgtext').html('<br>正在检测用户名是否可用......');

	$.ajax({
	type: "GET",
	dataType: "xml",
	url: "./ajax.php",
	data:   "do=checkPP&ppName="+username,
	success: function(xml){ 
				var code = $("/result/code",xml).text();
				var desc = $("/result/desc",xml).text();				
				$('#username_msgtext').html('<br>'+desc);
				$('#username_msgtext').css('color','green');
			} 
	}); 
}

//与jquery冲突关闭
function $2(id)
{
	return document.getElementById(id);
}


function rightTop(obj){
	var win = getWinSize();
	with (obj) {

		style.left = (win.width - offsetWidth)+'px';
		style.top = (win.height  + document.documentElement.scrollTop)+'px';
		style.position = "absolute";
		style.display = '';
		style.left = (win.width - offsetWidth)+'px';
		style.top = (win.height  + document.documentElement.scrollTop)+'px';
	}
}

function middle(obj){
	var win = getWinSize();
	with (obj) {
		style.left = (win.width - offsetWidth)/2+'px';
		style.top = (win.height - offsetHeight)/2 + document.documentElement.scrollTop+'px';
		style.position = "absolute";
		style.display = '';
		style.left = (win.width - offsetWidth)/2+'px';
		style.top = (win.height - offsetHeight)/2 + document.documentElement.scrollTop+'px';
	}
}


function getWinSize(obj) {
	var windowWidth, windowHeight;
	if(obj) {
		target = obj.document;
	} else {
		target = document;
	}
	if (self.innerHeight) {
		if(obj) {
			target = obj.self;
		} else {
			target = self;
		}
		windowWidth = target.innerWidth;
		windowHeight = target.innerHeight;
	} else if (target.documentElement && target.documentElement.clientHeight) {
		windowWidth = target.documentElement.clientWidth;
		windowHeight = target.documentElement.clientHeight;
	} else if (target.body) {
		windowWidth = target.body.clientWidth;
		windowHeight = target.body.clientHeight;
	}
	return {width:parseInt(windowWidth),height:parseInt(windowHeight)};
}


function urlEncode(str){ 
  var ret=""; 
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    tt += chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
} 



function urlDecode(str){ 
  var ret=""; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    if(chr == "+"){ 
      ret+=" "; 
    }else if(chr=="%"){ 
     var asc = str.substring(i+1,i+3); 
     if(parseInt("0x"+asc)>0x7f){ 
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
      i+=5; 
     }else{ 
      ret+=asc2str(parseInt("0x"+asc)); 
      i+=2; 
     } 
    }else{ 
      ret+= chr; 
    } 
  } 
  return ret; 
} 